<!DOCTYPE HTML>
<html>
<head>
<title>ErrorLevel | AutoHotkey</title>
<meta name="description" content="ErrorLevel is a built-in variable that is set to indicate the success or failure of some of the commands, functions and GUI/Control events." />
<meta name="ahk:equiv-v2" content="AutoHotkey.htm" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>

<body>
<h1>ErrorLevel</h1>

<p>这是表示一些命令执行成功与否的内置变量(有些命令不会改变 ErrorLevel 的值). 值为 0 时通常表示成功, 而其他值一般表示失败. 您也可以自己设置 ErrorLevel 的值.</p>
<p>特别有意义的是 <a href="../commands/Run.htm">RunWait</a> 会把 ErrorLevel 设置为它所运行程序的退出代码. 大多数程序在成功完成时会产生退出代码零.</p>
<p>每个<a href="Threads.htm">线程</a>会保持它自己的 ErrorLevel 的值, 这意味着如果<a href="Threads.htm">当前线程</a>被其他线程中断, 那么当原始线程恢复时它仍会拥有它原来的 ErrorLevel 值, 而不是由中断线程设置的 ErrorLevel 值.</p>
<p class="note"><strong>注意</strong>: 由于一些命令会设置大于 1 的 ErrorLevel 值, 所以最好不要检查 ErrorLevel 是否大于 1, 而是检查它是否等于零.</p>
<p>下面的列表包含了设置 ErrorLevel 的所有命令, 函数和 GUI/Control 事件, 包括可能的 ErrorLevel 值:</p>
<table class="info">
    <tr><td><a href="../commands/ClipWait.htm">ClipWait</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Control.htm">Control</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlClick.htm">ControlClick</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlFocus.htm">ControlFocus</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlGet.htm">ControlGet</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlGetFocus.htm">ControlGetFocus</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlGetText.htm">ControlGetText</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlMove.htm">ControlMove</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlSend.htm">ControlSend / ControlSendRaw</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/ControlSetText.htm">ControlSetText</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/DllCall.htm">DllCall()</a></td><td>0, -1, -2, -3, -4, <em>n</em>, A<em>n</em></td></tr>
    <tr><td><a href="../commands/Drive.htm">Drive</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/DriveGet.htm">DriveGet</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/EnvSet.htm">EnvSet</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/EnvUpdate.htm">EnvUpdate</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileAppend.htm">FileAppend</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileCopy.htm">FileCopy</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileCopyDir.htm">FileCopyDir</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileCreateDir.htm">FileCreateDir</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileCreateShortcut.htm">FileCreateShortcut</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileDelete.htm">FileDelete</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileGetAttrib.htm">FileGetAttrib</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetShortcut.htm">FileGetShortcut</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetSize.htm">FileGetSize</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetTime.htm">FileGetTime</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileGetVersion.htm">FileGetVersion</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileInstall.htm">FileInstall</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileMove.htm">FileMove</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileMoveDir.htm">FileMoveDir</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileRead.htm">FileRead</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileReadLine.htm">FileReadLine</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileRecycle.htm">FileRecycle</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileRecycleEmpty.htm">FileRecycleEmpty</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileRemoveDir.htm">FileRemoveDir</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileSelectFile.htm">FileSelectFile</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileSelectFolder.htm">FileSelectFolder</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/FileSetAttrib.htm">FileSetAttrib</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/FileSetTime.htm">FileSetTime</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/GroupActivate.htm">GroupActivate</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Gui.htm#GuiSize">Gui: GuiSize event</a></td><td>0, 1, 2</td></tr>
    <tr><td><a href="../commands/Gui.htm#GuiDropFiles">Gui: GuiDropFiles event</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/GuiControl.htm">GuiControl</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/GuiControlGet.htm">GuiControlGet</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/GuiControls.htm#Link">Gui control: Link click event</a></td><td><em>字符串</em></td></tr>
    <tr><td><a href="../commands/GuiControls.htm#Custom">Gui control: Custom event</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/ListView.htm#ItemChanged">Gui control: ListView item change event</a></td><td>"SsFfCc" 的子集</td></tr>
    <tr><td><a href="../commands/Hotkey.htm">Hotkey</a></td><td>0, 1, 2, 3, 4, 5, 6, 98, 99</td></tr>
    <tr><td><a href="../commands/ImageSearch.htm">ImageSearch</a></td><td>0, 1, 2</td></tr>
    <tr><td><a href="../commands/IniDelete.htm">IniDelete</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/IniWrite.htm">IniWrite</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Input.htm">Input</a></td><td>0, 1, NewInput, Max, Timeout, Match, EndKey:Name</td></tr>
    <tr><td><a href="../commands/InputBox.htm">InputBox</a></td><td>0, 1, 2</td></tr>
    <tr><td><a href="../commands/KeyWait.htm">KeyWait</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Menu.htm">Menu</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/PixelGetColor.htm">PixelGetColor</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/PixelSearch.htm">PixelSearch</a></td><td>0, 1, 2</td></tr>
    <tr><td><a href="../commands/PostMessage.htm">PostMessage</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Process.htm">Process</a></td><td>0, <em>PID</em></td></tr>
    <tr><td><a href="../commands/RegDelete.htm">RegDelete</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/RegExMatch.htm">RegExMatch()</a></td><td>0, <em>字符串</em>, -<em>n</em></td></tr>
    <tr><td><a href="../commands/RegExReplace.htm">RegExReplace()</a></td><td>0, <em>字符串</em>, -<em>n</em></td></tr>
    <tr><td><a href="../commands/RegRead.htm">RegRead</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/RegWrite.htm">RegWrite</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Run.htm">Run</a></td><td>0, ERROR</td></tr>
    <tr><td><a href="../commands/Run.htm">RunWait</a></td><td><em>n</em>, ERROR</td></tr>
    <tr><td><a href="../commands/PostMessage.htm">SendMessage</a></td><td>FAIL, <em>n</em></td></tr>
    <tr><td><a href="../commands/SetWorkingDir.htm">SetWorkingDir</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/Sort.htm#unique">Sort: U option</a></td><td>0, <em>n</em></td></tr>
    <tr><td><a href="../commands/SoundGet.htm">SoundGet</a></td><td>0, <em>字符串</em></td></tr>
    <tr><td><a href="../commands/SoundGetWaveVolume.htm">SoundGetWaveVolume</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/SoundPlay.htm">SoundPlay</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/SoundSet.htm">SoundSet</a></td><td>0, <em>字符串</em></td></tr>
    <tr><td><a href="../commands/SoundSetWaveVolume.htm">SoundSetWaveVolume</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/StatusBarGetText.htm">StatusBarGetText</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/StatusBarWait.htm">StatusBarWait</a></td><td>0, 1, 2</td></tr>
    <tr><td><a href="../commands/StringGetPos.htm">StringGetPos</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/StringReplace.htm">StringReplace</a></td><td>0, 1, <em>n</em></td></tr>
    <tr><td><a href="../commands/URLDownloadToFile.htm">UrlDownloadToFile</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinGetText.htm">WinGetText</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinMenuSelectItem.htm">WinMenuSelectItem</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinSet.htm">WinSet Style/ExStyle/Region</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinWait.htm">WinWait</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinWaitActive.htm">WinWaitActive / WinWaitNotActive</a></td><td>0, 1</td></tr>
    <tr><td><a href="../commands/WinWaitClose.htm">WinWaitClose</a></td><td>0, 1</td></tr>
</table>
<h2>示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>WinWait, MyWindow, , 1
if ErrorLevel   <em>; 即既不是空值, 也不是零.</em>
    MsgBox, The window does not exist.
else
    MsgBox, The window exists.</pre>
</div>
</body>
</html>